package com.cc.crm.web;

import com.cc.crm.entity.SalChance;
import com.cc.crm.service.SaleChanceService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2020-12-29 16:12
 */
@Controller
@RequestMapping("/sale")
public class SaleChanceController {

    @Autowired
    private SaleChanceService saleChaceService;

    @RequestMapping("/list")
    public String  list(Model model,
                        @RequestParam(value = "pNum",defaultValue = "1") int pNum,
                        @RequestParam(value = "pageSize",defaultValue = "2") int pageSize){
        listSaleChace(model, pNum, pageSize);
        //3.跳转页面
        return "~sale/list";
    }

    @RequestMapping("/template")
    public String template(Model model,
                           @RequestParam(value = "pNum",defaultValue = "1") int pNum,
                           @RequestParam(value = "pageSize",defaultValue = "2") int pageSize){
        listSaleChace(model, pNum, pageSize);
        return "~sale/listTemplate";
    }

    private void listSaleChace(Model model, @RequestParam(value = "pNum", defaultValue = "1") int pNum, @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        //1.调用saleService的分页查询的方法
        List<SalChance> salChanceList = saleChaceService.list(pNum, pageSize);
        //2.绑定数据
        Page<SalChance> pageSalChance = (Page<SalChance>) salChanceList;
//        pageSalChance
        model.addAttribute("salChanceList", salChanceList);
        model.addAttribute("pageSalChance", pageSalChance);
    }


}


